﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Wicresoft.SelfService.BL
{
    public class FileContentTypeHelper
    {
        #region contentType
        static Dictionary<String, String> dic = new Dictionary<String, String>();

         static FileContentTypeHelper()
        {
            dic.Add("abs", "audio/x-mpeg");

            dic.Add("ai", "application/postscript");

            dic.Add("aif", "audio/x-aiff");

            dic.Add("aifc", "audio/x-aiff");

            dic.Add("aiff", "audio/x-aiff");

            dic.Add("aim", "application/x-aim");

            dic.Add("art", "image/x-jg");

            dic.Add("asf", "video/x-ms-asf");

            dic.Add("asx", "video/x-ms-asf");

            dic.Add("au", "audio/basic");

            dic.Add("avi", "video/x-msvideo");

            dic.Add("avx", "video/x-rad-screenplay");

            dic.Add("bcpio", "application/x-bcpio");

            dic.Add("bin", "application/octet-stream");

            dic.Add("bmp", "image/bmp");

            dic.Add("body", "text/html");

            dic.Add("cdf", "application/x-cdf");

            dic.Add("cer", "application/x-x509-ca-cert");

            dic.Add("class", "application/java");

            dic.Add("cpio", "application/x-cpio");

            dic.Add("csh", "application/x-csh");

            dic.Add("css", "text/css");

            dic.Add("dib", "image/bmp");

            dic.Add("doc", "application/msword");

            dic.Add("dtd", "application/xml-dtd");

            dic.Add("dv", "video/x-dv");

            dic.Add("dvi", "application/x-dvi");

            dic.Add("eps", "application/postscript");

            dic.Add("etx", "text/x-setext");

            dic.Add("exe", "application/octet-stream");

            dic.Add("gif", "image/gif");

            dic.Add("gtar", "application/x-gtar");

            dic.Add("gz", "application/x-gzip");

            dic.Add("hdf", "application/x-hdf");

            dic.Add("hqx", "application/mac-binhex40");

            dic.Add("htc", "text/x-component");

            dic.Add("htm", "text/html");

            dic.Add("html", "text/html");

            dic.Add("ief", "image/ief");

            dic.Add("jad", "text/vnd.sun.j2me.app-descriptor");

            dic.Add("jar", "application/java-archive");

            dic.Add("java", "text/plain");

            dic.Add("jnlp", "application/x-java-jnlp-file");

            dic.Add("jpe", "image/jpeg");

            dic.Add("jpeg", "image/jpeg");

            dic.Add("jpg", "image/jpeg");

            dic.Add("js", "text/javascript");

            dic.Add("jsf", "text/plain");

            dic.Add("jspf", "text/plain");

            dic.Add("kar", "audio/x-midi");

            dic.Add("latex", "application/x-latex");

            dic.Add("m3u", "audio/x-mpegurl");

            dic.Add("mac", "image/x-macpaint");

            dic.Add("man", "application/x-troff-man");

            dic.Add("mathml", "application/mathml+xml");

            dic.Add("me", "application/x-troff-me");

            dic.Add("mid", "audio/x-midi");

            dic.Add("midi", "audio/x-midi");

            dic.Add("mif", "application/x-mif");

            dic.Add("mov", "video/quicktime");

            dic.Add("movie", "video/x-sgi-movie");

            dic.Add("mp1", "audio/x-mpeg");

            dic.Add("mp2", "audio/x-mpeg");

            dic.Add("mp3", "audio/x-mpeg");

            dic.Add("mp4", "video/mp4");

            dic.Add("mpa", "audio/x-mpeg");

            dic.Add("mpe", "video/mpeg");

            dic.Add("mpeg", "video/mpeg");

            dic.Add("mpega", "audio/x-mpeg");

            dic.Add("mpg", "video/mpeg");

            dic.Add("mpv2", "video/mpeg2");

            dic.Add("ms", "application/x-wais-source");

            dic.Add("nc", "application/x-netcdf");

            dic.Add("oda", "application/oda");

            dic.Add("odb", "application/vnd.oasis.opendocument.database");

            dic.Add("odc", "application/vnd.oasis.opendocument.chart");

            dic.Add("odf", "application/vnd.oasis.opendocument.formula");

            dic.Add("odg", "application/vnd.oasis.opendocument.graphics");

            dic.Add("odi", "application/vnd.oasis.opendocument.image");

            dic.Add("odm", "application/vnd.oasis.opendocument.text-master");

            dic.Add("odp", "application/vnd.oasis.opendocument.presentation");

            dic.Add("ods", "application/vnd.oasis.opendocument.spreadsheet");

            dic.Add("odt", "application/vnd.oasis.opendocument.text");

            dic.Add("ogg", "application/ogg");

            dic.Add("otg", "application/vnd.oasis.opendocument.graphics-template");

            dic.Add("oth", "application/vnd.oasis.opendocument.text-web");

            dic.Add("otp",
               "application/vnd.oasis.opendocument.presentation-template");

            dic.Add("ots",
               "application/vnd.oasis.opendocument.spreadsheet-template ");

            dic.Add("ott", "application/vnd.oasis.opendocument.text-template");

            dic.Add("pbm", "image/x-portable-bitmap");

            dic.Add("pct", "image/pict");

            dic.Add("pdf", "application/pdf");

            dic.Add("pgm", "image/x-portable-graymap");

            dic.Add("pic", "image/pict");

            dic.Add("pict", "image/pict");

            dic.Add("pls", "audio/x-scpls");

            dic.Add("png", "image/png");

            dic.Add("pnm", "image/x-portable-anymap");

            dic.Add("pnt", "image/x-macpaint");

            dic.Add("ppm", "image/x-portable-pixmap");

            dic.Add("ppt", "application/powerpoint");
            dic.Add("pptx", "application/powerpoint");

            dic.Add("ps", "application/postscript");

            dic.Add("psd", "image/x-photoshop");

            dic.Add("qt", "video/quicktime");

            dic.Add("qti", "image/x-quicktime");

            dic.Add("qtif", "image/x-quicktime");

            dic.Add("ras", "image/x-cmu-raster");

            dic.Add("rdf", "application/rdf+xml");

            dic.Add("rgb", "image/x-rgb");

            dic.Add("rm", "application/vnd.rn-realmedia");

            dic.Add("roff", "application/x-troff");

            dic.Add("rtf", "application/rtf");

            dic.Add("rtx", "text/richtext");

            dic.Add("sh", "application/x-sh");

            dic.Add("shar", "application/x-shar");

            dic.Add("shtml", "text/x-server-parsed-html");

            dic.Add("smf", "audio/x-midi");

            dic.Add("sit", "application/x-stuffit");

            dic.Add("snd", "audio/basic");

            dic.Add("src", "application/x-wais-source");

            dic.Add("sv4cpio", "application/x-sv4cpio");

            dic.Add("sv4crc", "application/x-sv4crc");

            dic.Add("swf", "application/x-shockwave-flash");

            dic.Add("t", "application/x-troff");

            dic.Add("tar", "application/x-tar");

            dic.Add("tcl", "application/x-tcl");

            dic.Add("tex", "application/x-tex");

            dic.Add("texi", "application/x-texinfo");

            dic.Add("texinfo", "application/x-texinfo");

            dic.Add("tif", "image/tiff");

            dic.Add("tiff", "image/tiff");

            dic.Add("tr", "application/x-troff");

            dic.Add("tsv", "text/tab-separated-values");

            dic.Add("ulw", "audio/basic");

            dic.Add("ustar", "application/x-ustar");

            dic.Add("vxml", "application/voicexml+xml");

            dic.Add("xbm", "image/x-xbitmap");

            dic.Add("xht", "application/xhtml+xml");

            dic.Add("xhtml", "application/xhtml+xml");

            dic.Add("xml", "application/xml");

            dic.Add("xpm", "image/x-xpixmap");

            dic.Add("xsl", "application/xml");

            dic.Add("xslt", "application/xslt+xml");

            dic.Add("xul", "application/vnd.mozilla.xul+xml");

            dic.Add("xwd", "image/x-xwindowdump");

            dic.Add("wav", "audio/x-wav");

            dic.Add("svg", "image/svg+xml");

            dic.Add("svgz", "image/svg+xml");

            dic.Add("vsd", "application/x-visio");

            dic.Add("wbmp", "image/vnd.wap.wbmp");

            dic.Add("wml", "text/vnd.wap.wml");

            dic.Add("wmlc", "application/vnd.wap.wmlc");

            dic.Add("wmls", "text/vnd.wap.wmlscript");

            dic.Add("wmlscriptc", "application/vnd.wap.wmlscriptc");

            dic.Add("wmv", "video/x-ms-wmv");

            dic.Add("wrl", "x-world/x-vrml");

            dic.Add("wspolicy", "application/wspolicy+xml");

            dic.Add("Z", "application/x-compress");

            dic.Add("z", "application/x-compress");

            dic.Add("zip", "application/zip");
           
            dic.Add("xls", "application/vnd.ms-excel");

            dic.Add("xlsx", "application/vnd.ms-excel");

            dic.Add("docx", "application/msword");

            dic.Add("rar", "application/x-zip-compressed");
            dic.Add("txt", "text/plain");

        }

        #endregion

        public static string getFileContentType(String filename)
        {
            string suffix = filename.Substring(filename.LastIndexOf(".") + 1, filename.Length - filename.LastIndexOf(".")-1);
            try
            {
                return dic[suffix].ToString();
            }
            catch
            {
                return "application/octet-stream";
            }
        }

    }
}
